//
//  ERCaculatorView.m
//  ExchangeRate
//
//  Created by 方义强 on 15/11/7.
//  Copyright © 2015年 方义强. All rights reserved.
//

#import "ERCaculatorView.h"
#define kButtonHeight kSCREENHEIGHT / 12
#define kButtonWidth kSCREENWIDTH / 4

@interface ERCaculatorView ()

@property (nonatomic, strong) NSMutableArray *arr;

@end

@implementation ERCaculatorView

- (NSMutableArray *)arr
{
    if (!_arr)
    {
        _arr = [NSMutableArray arrayWithObjects:
                @"number_key_7",
                @"number_key_8",
                @"number_key_9",
                @"number_key_11",
                @"number_key_4",
                @"number_key_5",
                @"number_key_6",
                @"number_key_12",
                @"number_key_1",
                @"number_key_2",
                @"number_key_3",
                @"number_key_13",
                @"number_key_14",
                @"number_key_0",
                @"number_key_15",
                @"number_key_16",
                nil];
    }
    return _arr;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        
        _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kSCREENWIDTH, kSCREENHEIGHT / 3)];
        _imageView.image = [UIImage imageNamed:@"number_bg@2x.png"];
        _imageView.userInteractionEnabled = YES;
        [self addSubview:_imageView];
        
        CGFloat buttonHeight = 0;
        for (int i = 0; i < self.arr.count; i++)
        {
            
            int num = i  % 4;
            UIButton * button = [UIButton buttonWithType:(UIButtonTypeCustom)];
            if (num == 0 && i != 0)
            {
                buttonHeight += kSCREENHEIGHT / 12;
                
            }
            if (num == 3) {
//                [button setTitleColor:[UIColor colorWithRed:0.032 green:0.777 blue:0.929 alpha:1.000] forState:(UIControlStateNormal)];
            }
            else
            {
//                [button setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
            }
            button.frame = CGRectMake(kButtonWidth * num, buttonHeight, kButtonWidth, kButtonHeight);
            button.tag = 100 + i;
            button.backgroundColor = [UIColor clearColor];
            [button setImage:[UIImage imageNamed:self.arr[i]] forState:(UIControlStateNormal)];
            [_imageView addSubview: button];
        }
        
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
